package org.springblade.modules.system.controller;

import io.swagger.annotations.ApiParam;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R;
import org.springblade.modules.admin.entity.ZgRedeployConfig;
import org.springblade.modules.system.entity.TenantConfig;
import org.springblade.modules.system.service.TenantConfigService;
import org.springblade.modules.system.vo.config.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Map;

/**
 * @Date 10:26 2023/4/6
 * @Description {
 *   租户业务配置
 * }
 * @Author lsay
 **/
@RestController
@RequestMapping("/tenant/config")
public class TenantConfigController {

	@Autowired
	private TenantConfigService tenantConfigService;

	/**
	 * @Author lsay
	 * @Description {
	 *   查询租户业务配置
	 * }
	 * @Date 10:48 2023/4/6
	 * @return
	 **/
	@GetMapping()
	public R<TenantConfig> getTenantConfig(){
		return R.data(tenantConfigService.getTenantConfig(AuthUtil.getTenantId()));
	}

	/**
	 * @Author lsay
	 * @Description {
	 *   更新租户业务配置
	 * }
	 * @Date 10:48 2023/4/6
	 * @return
	 **/
	@PostMapping()
	public R<Boolean> updateTenantConfig(@RequestBody Map<String,Object> configMap){
		return R.data(tenantConfigService.updateTenantConfig(configMap,AuthUtil.getTenantId()));
	}

	/**
	 * @Author lsay
	 * @Description {
	 *   更新租户业务配置
	 * }
	 * @Date 9:51 2023/9/6
	 * @Param
	 **/
	@PostMapping("/update")
	public R<Boolean> update(@RequestBody TenantConfig tenantConfig){
		return R.data(tenantConfigService.updateDetail(tenantConfig,AuthUtil.getTenantId()));
	}

	/**
	 * @Author lsay
	 * @Description {
	 *   更新租户业务配置
	 * }
	 * @Date 16:03 2025/4/16
	 * @Param
	 **/
	@PostMapping("/update/zg/redeploy")
	public R<Boolean> updateZgRedeploy(@RequestBody ZgRedeployConfig zgRedeployConfig){
		return R.data(tenantConfigService.updateZgRedeploy(zgRedeployConfig,AuthUtil.getTenantId()));
	}

	/**
	 * 更新困人报警通知设置
	 * @param config
	 * @return
	 */
	@PostMapping("/update/alarm/notify")
	public R<Boolean> updateAlarmNotify(@Valid @RequestBody AlarmNotifyConfig config){
		return R.data(tenantConfigService.updateAlarmNotify(config));
	}

	/**
	 * 更新自动报警设置
	 * @param config
	 * @return
	 */
	@PostMapping("/update/alarm")
	public R<Boolean> updateAlarm(@Valid @RequestBody AlarmConfig config){
		return R.data(tenantConfigService.updateAlarm(config));
	}

	/**
	 * 更新救援签到设置
	 * @param config
	 * @return
	 */
	@PostMapping("/update/rescue/sign")
	public R<Boolean> updateRescueSign(@Valid @RequestBody RescueSignConfig config){
		return R.data(tenantConfigService.updateRescueSign(config));
	}

	/**
	 * 更新告警标签配置
	 * @param config
	 * @return
	 */
	@PostMapping("/update/alarm/label")
	public R<Boolean> updateAlarmLabel(@Valid @RequestBody AlarmLabelExtConfig config){
		return R.data(tenantConfigService.updateAlarmLabel(config));
	}

	/**
	 * 获取AI服务报警开关状态
	 */
	@GetMapping("ai/service/alarm/enable/status")
	public R<AiServiceAlarmEnableStatusVO> getAiServiceAlarmEnableStatus(@ApiParam(value = "群聊id", required = true) @RequestParam String groupId){
		return R.data(tenantConfigService.getAiServiceAlarmEnableStatus(groupId));
	}
}
